package com.erhairent.tools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class CarUpdate {

	public boolean updateSQL(String sql, Object... params) {

		try {
			Connection conn = DBHelp.getInstance().getConnection();
			// -- 设置自动提交
			conn.setAutoCommit(true);

			// -- 通过链接获取PreparedStatement;
			PreparedStatement pStatement = conn.prepareStatement(sql);
			// -- 替换占位符

			// -- 获取SQL语句中占位符的数量
			int count = pStatement.getParameterMetaData().getParameterCount();
			for (int i = 0; i < count; i++) {
				pStatement.setObject(i + 1, params[i]);
			}

			// -- 执行sql语句
			int i = pStatement.executeUpdate();
			if (i > 0) {
				return true;
			}

		} catch (SQLException e) {

			return false;
			
		}
		return false;
	}
}
